package P1300;

import java.util.Scanner;

/**
 * @author: zhouyang
 * @descrpition:
 * @time: 2019-10-18 14:06
 */
public class P1328_生活大爆炸版石头剪刀布 {
    public static void main(String[] args) {
        int[][] score =new int[][]{{0,0,1,1,0},{1,0,0,1,0},{0,1,0,0,1},{0,0,1,0,1},{1,1,0,0,0}};
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();//总共N次猜拳
        int A = scanner.nextInt();//A的周期
        int B = scanner.nextInt();//B的周期
        int[] a = new int[A];
        int[] b = new int[B];
        for(int i=0;i<A;++i) a[i] = scanner.nextInt();
        for(int i=0;i<B;++i) b[i] = scanner.nextInt();
        scanner.close();
        int r1=0,r2=0;
        for(int i=0;i<N;++i){
            int d1 = i%A;
            int d2 = i%B;
            r1 += score[a[d1]][b[d2]];
            r2 += score[b[d2]][a[d1]];
        }
        System.out.printf("%d %d\n",r1,r2);
    }
}
